﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace GUI
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		private const string MUTEX_NAME = "ObjectShelve{7F14E174-BC03-42c7-AABF-4F955D07ABE5}";
		private static System.Threading.Mutex mutex;

		public App()
		{
			// check for another instance
			bool singleInstance;
			mutex = new System.Threading.Mutex(false, MUTEX_NAME, out singleInstance);

			if (!singleInstance)
			{
				MessageBox.Show("Another instance of the application is already running.", "Single instance only", MessageBoxButton.OK, MessageBoxImage.Warning);
				Shutdown(-1);
			}
			GC.KeepAlive(mutex);
		}

		protected override void OnExit(ExitEventArgs e)
		{
			mutex.Close();
			mutex = null;
			base.OnExit(e);
		}
	}
}
